package com.raspberryCar.model;

import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;

public class MoveCheck implements Runnable {

  private GpioPinDigitalInput input0;
  private SmallCar car;

  public MoveCheck(GpioPinDigitalInput input0, SmallCar car) {
    this.input0 = input0;
    this.car = car;
  }

  @Override
  public void run() {
    int count1 = 0;
    while (true) {
      boolean high = false;
      boolean low = false;
      while (true) {
        if (!high && input0.getState() == PinState.HIGH) {
          high = true;
        }
        if (high && !low && input0.getState() == PinState.LOW) {
          low = true;
        }
        if (low && high) {
          count1++;
          break;
        }
      }

      if (count1 == 20) {
        // stop();
//         car.stop();
        count1 = 0;
        System.out.println("stop+++++");
        // break;
      }
    }
  }
}
